{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using Theano backend.\n",
      "Using gpu device 0: GeForce GTX 960 (CNMeM is disabled, cuDNN 4007)\n"
     ]
    }
   ],
   "source": [
    "from keras.models import Sequential\n",
    "from keras.layers import Dense, Activation, TimeDistributed\n",
    "from keras.optimizers import Adam\n",
    "from keras.layers.recurrent import LSTM\n",
    "\n",
    "import numpy\n",
    "import matplotlib.pyplot as plt\n",
    "from mpl_toolkits.mplot3d import Axes3D\n",
    "from matplotlib import cm\n",
    "%matplotlib notebook "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "feature_length = 32\n",
    "seq_length = 80\n",
    "inteval = 0.1\n",
    "\n",
    "# RNN model using LSTM\n",
    "model = Sequential()\n",
    "model.add(LSTM(256, return_sequences=True, input_dim=feature_length))\n",
    "model.add(TimeDistributed(Dense(feature_length)))\n",
    "#model.add(Activation('tanh'))\n",
    "model.compile(loss='mean_squared_error', optimizer=Adam())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# generate data based on f\n",
    "def gen_train_data(f, data_range, feature_len, seq_len):\n",
    "    x = numpy.arange(*data_range)\n",
    "    y = f(x) \n",
    "    s = feature_len // 2\n",
    "    nb_samples = (len(y) - feature_len - s) // seq_len\n",
    "    X = numpy.zeros((nb_samples, seq_len, feature_len))\n",
    "    Y = numpy.zeros((nb_samples, seq_len, feature_len))\n",
    "    for i in range(nb_samples):\n",
    "        for j in range(seq_len//s):\n",
    "            X[i,j] = y[i*seq_len+j*s:i*seq_len+j*s+feature_len]\n",
    "            # predict next s element\n",
    "            Y[i,j] = y[i*seq_len+j*s+s:i*seq_len+j*s+feature_len+s]\n",
    "    return X, Y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/500\n",
      "24/24 [==============================] - 0s - loss: 0.0335\n",
      "Epoch 2/500\n",
      "24/24 [==============================] - 0s - loss: 0.0312\n",
      "Epoch 3/500\n",
      "24/24 [==============================] - 0s - loss: 0.0290\n",
      "Epoch 4/500\n",
      "24/24 [==============================] - 0s - loss: 0.0270\n",
      "Epoch 5/500\n",
      "24/24 [==============================] - 0s - loss: 0.0250\n",
      "Epoch 6/500\n",
      "24/24 [==============================] - 0s - loss: 0.0232\n",
      "Epoch 7/500\n",
      "24/24 [==============================] - 0s - loss: 0.0214\n",
      "Epoch 8/500\n",
      "24/24 [==============================] - 0s - loss: 0.0196\n",
      "Epoch 9/500\n",
      "24/24 [==============================] - 0s - loss: 0.0180\n",
      "Epoch 10/500\n",
      "24/24 [==============================] - 0s - loss: 0.0163\n",
      "Epoch 11/500\n",
      "24/24 [==============================] - 0s - loss: 0.0147\n",
      "Epoch 12/500\n",
      "24/24 [==============================] - 0s - loss: 0.0132\n",
      "Epoch 13/500\n",
      "24/24 [==============================] - 0s - loss: 0.0118\n",
      "Epoch 14/500\n",
      "24/24 [==============================] - 0s - loss: 0.0104\n",
      "Epoch 15/500\n",
      "24/24 [==============================] - 0s - loss: 0.0091\n",
      "Epoch 16/500\n",
      "24/24 [==============================] - 0s - loss: 0.0079\n",
      "Epoch 17/500\n",
      "24/24 [==============================] - 0s - loss: 0.0069\n",
      "Epoch 18/500\n",
      "24/24 [==============================] - 0s - loss: 0.0060\n",
      "Epoch 19/500\n",
      "24/24 [==============================] - 0s - loss: 0.0052\n",
      "Epoch 20/500\n",
      "24/24 [==============================] - 0s - loss: 0.0046\n",
      "Epoch 21/500\n",
      "24/24 [==============================] - 0s - loss: 0.0040\n",
      "Epoch 22/500\n",
      "24/24 [==============================] - 0s - loss: 0.0036\n",
      "Epoch 23/500\n",
      "24/24 [==============================] - 0s - loss: 0.0032\n",
      "Epoch 24/500\n",
      "24/24 [==============================] - 0s - loss: 0.0029\n",
      "Epoch 25/500\n",
      "24/24 [==============================] - 0s - loss: 0.0026\n",
      "Epoch 26/500\n",
      "24/24 [==============================] - 0s - loss: 0.0022\n",
      "Epoch 27/500\n",
      "24/24 [==============================] - 0s - loss: 0.0019\n",
      "Epoch 28/500\n",
      "24/24 [==============================] - 0s - loss: 0.0016\n",
      "Epoch 29/500\n",
      "24/24 [==============================] - 0s - loss: 0.0013\n",
      "Epoch 30/500\n",
      "24/24 [==============================] - 0s - loss: 0.0011\n",
      "Epoch 31/500\n",
      "24/24 [==============================] - 0s - loss: 9.1718e-04\n",
      "Epoch 32/500\n",
      "24/24 [==============================] - 0s - loss: 7.7728e-04\n",
      "Epoch 33/500\n",
      "24/24 [==============================] - 0s - loss: 6.7554e-04\n",
      "Epoch 34/500\n",
      "24/24 [==============================] - 0s - loss: 6.0289e-04\n",
      "Epoch 35/500\n",
      "24/24 [==============================] - 0s - loss: 5.4927e-04\n",
      "Epoch 36/500\n",
      "24/24 [==============================] - 0s - loss: 5.0644e-04\n",
      "Epoch 37/500\n",
      "24/24 [==============================] - 0s - loss: 4.6847e-04\n",
      "Epoch 38/500\n",
      "24/24 [==============================] - 0s - loss: 4.3198e-04\n",
      "Epoch 39/500\n",
      "24/24 [==============================] - 0s - loss: 3.9617e-04\n",
      "Epoch 40/500\n",
      "24/24 [==============================] - 0s - loss: 3.6190e-04\n",
      "Epoch 41/500\n",
      "24/24 [==============================] - 0s - loss: 3.3071e-04\n",
      "Epoch 42/500\n",
      "24/24 [==============================] - 0s - loss: 3.0396e-04\n",
      "Epoch 43/500\n",
      "24/24 [==============================] - 0s - loss: 2.8210e-04\n",
      "Epoch 44/500\n",
      "24/24 [==============================] - 0s - loss: 2.6476e-04\n",
      "Epoch 45/500\n",
      "24/24 [==============================] - 0s - loss: 2.5090e-04\n",
      "Epoch 46/500\n",
      "24/24 [==============================] - 0s - loss: 2.3897e-04\n",
      "Epoch 47/500\n",
      "24/24 [==============================] - 0s - loss: 2.2760e-04\n",
      "Epoch 48/500\n",
      "24/24 [==============================] - 0s - loss: 2.1600e-04\n",
      "Epoch 49/500\n",
      "24/24 [==============================] - 0s - loss: 2.0377e-04\n",
      "Epoch 50/500\n",
      "24/24 [==============================] - 0s - loss: 1.9094e-04\n",
      "Epoch 51/500\n",
      "24/24 [==============================] - 0s - loss: 1.7797e-04\n",
      "Epoch 52/500\n",
      "24/24 [==============================] - 0s - loss: 1.6522e-04\n",
      "Epoch 53/500\n",
      "24/24 [==============================] - 0s - loss: 1.5290e-04\n",
      "Epoch 54/500\n",
      "24/24 [==============================] - 0s - loss: 1.4120e-04\n",
      "Epoch 55/500\n",
      "24/24 [==============================] - 0s - loss: 1.3015e-04\n",
      "Epoch 56/500\n",
      "24/24 [==============================] - 0s - loss: 1.1977e-04\n",
      "Epoch 57/500\n",
      "24/24 [==============================] - 0s - loss: 1.1013e-04\n",
      "Epoch 58/500\n",
      "24/24 [==============================] - 0s - loss: 1.0128e-04\n",
      "Epoch 59/500\n",
      "24/24 [==============================] - 0s - loss: 9.3317e-05\n",
      "Epoch 60/500\n",
      "24/24 [==============================] - 0s - loss: 8.6313e-05\n",
      "Epoch 61/500\n",
      "24/24 [==============================] - 0s - loss: 8.0274e-05\n",
      "Epoch 62/500\n",
      "24/24 [==============================] - 0s - loss: 7.5101e-05\n",
      "Epoch 63/500\n",
      "24/24 [==============================] - 0s - loss: 7.0667e-05\n",
      "Epoch 64/500\n",
      "24/24 [==============================] - 0s - loss: 6.6804e-05\n",
      "Epoch 65/500\n",
      "24/24 [==============================] - 0s - loss: 6.3360e-05\n",
      "Epoch 66/500\n",
      "24/24 [==============================] - 0s - loss: 6.0233e-05\n",
      "Epoch 67/500\n",
      "24/24 [==============================] - 0s - loss: 5.7366e-05\n",
      "Epoch 68/500\n",
      "24/24 [==============================] - 0s - loss: 5.4757e-05\n",
      "Epoch 69/500\n",
      "24/24 [==============================] - 0s - loss: 5.2420e-05\n",
      "Epoch 70/500\n",
      "24/24 [==============================] - 0s - loss: 5.0366e-05\n",
      "Epoch 71/500\n",
      "24/24 [==============================] - 0s - loss: 4.8592e-05\n",
      "Epoch 72/500\n",
      "24/24 [==============================] - 0s - loss: 4.7057e-05\n",
      "Epoch 73/500\n",
      "24/24 [==============================] - 0s - loss: 4.5694e-05\n",
      "Epoch 74/500\n",
      "24/24 [==============================] - 0s - loss: 4.4435e-05\n",
      "Epoch 75/500\n",
      "24/24 [==============================] - 0s - loss: 4.3220e-05\n",
      "Epoch 76/500\n",
      "24/24 [==============================] - 0s - loss: 4.1996e-05\n",
      "Epoch 77/500\n",
      "24/24 [==============================] - 0s - loss: 4.0750e-05\n",
      "Epoch 78/500\n",
      "24/24 [==============================] - 0s - loss: 3.9490e-05\n",
      "Epoch 79/500\n",
      "24/24 [==============================] - 0s - loss: 3.8229e-05\n",
      "Epoch 80/500\n",
      "24/24 [==============================] - 0s - loss: 3.6993e-05\n",
      "Epoch 81/500\n",
      "24/24 [==============================] - 0s - loss: 3.5804e-05\n",
      "Epoch 82/500\n",
      "24/24 [==============================] - 0s - loss: 3.4675e-05\n",
      "Epoch 83/500\n",
      "24/24 [==============================] - 0s - loss: 3.3612e-05\n",
      "Epoch 84/500\n",
      "24/24 [==============================] - 0s - loss: 3.2618e-05\n",
      "Epoch 85/500\n",
      "24/24 [==============================] - 0s - loss: 3.1691e-05\n",
      "Epoch 86/500\n",
      "24/24 [==============================] - 0s - loss: 3.0830e-05\n",
      "Epoch 87/500\n",
      "24/24 [==============================] - 0s - loss: 3.0028e-05\n",
      "Epoch 88/500\n",
      "24/24 [==============================] - 0s - loss: 2.9283e-05\n",
      "Epoch 89/500\n",
      "24/24 [==============================] - 0s - loss: 2.8584e-05\n",
      "Epoch 90/500\n",
      "24/24 [==============================] - 0s - loss: 2.7922e-05\n",
      "Epoch 91/500\n",
      "24/24 [==============================] - 0s - loss: 2.7290e-05\n",
      "Epoch 92/500\n",
      "24/24 [==============================] - 0s - loss: 2.6678e-05\n",
      "Epoch 93/500\n",
      "24/24 [==============================] - 0s - loss: 2.6084e-05\n",
      "Epoch 94/500\n",
      "24/24 [==============================] - 0s - loss: 2.5507e-05\n",
      "Epoch 95/500\n",
      "24/24 [==============================] - 0s - loss: 2.4951e-05\n",
      "Epoch 96/500\n",
      "24/24 [==============================] - 0s - loss: 2.4419e-05\n",
      "Epoch 97/500\n",
      "24/24 [==============================] - 0s - loss: 2.3915e-05\n",
      "Epoch 98/500\n",
      "24/24 [==============================] - 0s - loss: 2.3438e-05\n",
      "Epoch 99/500\n",
      "24/24 [==============================] - 0s - loss: 2.2984e-05\n",
      "Epoch 100/500\n",
      "24/24 [==============================] - 0s - loss: 2.2548e-05\n",
      "Epoch 101/500\n",
      "24/24 [==============================] - 0s - loss: 2.2125e-05\n",
      "Epoch 102/500\n",
      "24/24 [==============================] - 0s - loss: 2.1710e-05\n",
      "Epoch 103/500\n",
      "24/24 [==============================] - 0s - loss: 2.1302e-05\n",
      "Epoch 104/500\n",
      "24/24 [==============================] - 0s - loss: 2.0902e-05\n",
      "Epoch 105/500\n",
      "24/24 [==============================] - 0s - loss: 2.0513e-05\n",
      "Epoch 106/500\n",
      "24/24 [==============================] - 0s - loss: 2.0136e-05\n",
      "Epoch 107/500\n",
      "24/24 [==============================] - 0s - loss: 1.9772e-05\n",
      "Epoch 108/500\n",
      "24/24 [==============================] - 0s - loss: 1.9421e-05\n",
      "Epoch 109/500\n",
      "24/24 [==============================] - 0s - loss: 1.9083e-05\n",
      "Epoch 110/500\n",
      "24/24 [==============================] - 0s - loss: 1.8756e-05\n",
      "Epoch 111/500\n",
      "24/24 [==============================] - 0s - loss: 1.8439e-05\n",
      "Epoch 112/500\n",
      "24/24 [==============================] - 0s - loss: 1.8130e-05\n",
      "Epoch 113/500\n",
      "24/24 [==============================] - 0s - loss: 1.7828e-05\n",
      "Epoch 114/500\n",
      "24/24 [==============================] - 0s - loss: 1.7535e-05\n",
      "Epoch 115/500\n",
      "24/24 [==============================] - 0s - loss: 1.7249e-05\n",
      "Epoch 116/500\n",
      "24/24 [==============================] - 0s - loss: 1.6971e-05\n",
      "Epoch 117/500\n",
      "24/24 [==============================] - 0s - loss: 1.6701e-05\n",
      "Epoch 118/500\n",
      "24/24 [==============================] - 0s - loss: 1.6437e-05\n",
      "Epoch 119/500\n",
      "24/24 [==============================] - 0s - loss: 1.6181e-05\n",
      "Epoch 120/500\n",
      "24/24 [==============================] - 0s - loss: 1.5931e-05\n",
      "Epoch 121/500\n",
      "24/24 [==============================] - 0s - loss: 1.5687e-05\n",
      "Epoch 122/500\n",
      "24/24 [==============================] - 0s - loss: 1.5449e-05\n",
      "Epoch 123/500\n",
      "24/24 [==============================] - 0s - loss: 1.5216e-05\n",
      "Epoch 124/500\n",
      "24/24 [==============================] - 0s - loss: 1.4988e-05\n",
      "Epoch 125/500\n",
      "24/24 [==============================] - 0s - loss: 1.4766e-05\n",
      "Epoch 126/500\n",
      "24/24 [==============================] - 0s - loss: 1.4547e-05\n",
      "Epoch 127/500\n",
      "24/24 [==============================] - 0s - loss: 1.4333e-05\n",
      "Epoch 128/500\n",
      "24/24 [==============================] - 0s - loss: 1.4124e-05\n",
      "Epoch 129/500\n",
      "24/24 [==============================] - 0s - loss: 1.3918e-05\n",
      "Epoch 130/500\n",
      "24/24 [==============================] - 0s - loss: 1.3717e-05\n",
      "Epoch 131/500\n",
      "24/24 [==============================] - 0s - loss: 1.3521e-05\n",
      "Epoch 132/500\n",
      "24/24 [==============================] - 0s - loss: 1.3328e-05\n",
      "Epoch 133/500\n",
      "24/24 [==============================] - 0s - loss: 1.3140e-05\n",
      "Epoch 134/500\n",
      "24/24 [==============================] - 0s - loss: 1.2956e-05\n",
      "Epoch 135/500\n",
      "24/24 [==============================] - 0s - loss: 1.2775e-05\n",
      "Epoch 136/500\n",
      "24/24 [==============================] - 0s - loss: 1.2599e-05\n",
      "Epoch 137/500\n",
      "24/24 [==============================] - 0s - loss: 1.2426e-05\n",
      "Epoch 138/500\n",
      "24/24 [==============================] - 0s - loss: 1.2256e-05\n",
      "Epoch 139/500\n",
      "24/24 [==============================] - 0s - loss: 1.2090e-05\n",
      "Epoch 140/500\n",
      "24/24 [==============================] - 0s - loss: 1.1927e-05\n",
      "Epoch 141/500\n",
      "24/24 [==============================] - 0s - loss: 1.1767e-05\n",
      "Epoch 142/500\n",
      "24/24 [==============================] - 0s - loss: 1.1611e-05\n",
      "Epoch 143/500\n",
      "24/24 [==============================] - 0s - loss: 1.1457e-05\n",
      "Epoch 144/500\n",
      "24/24 [==============================] - 0s - loss: 1.1307e-05\n",
      "Epoch 145/500\n",
      "24/24 [==============================] - 0s - loss: 1.1159e-05\n",
      "Epoch 146/500\n",
      "24/24 [==============================] - 0s - loss: 1.1014e-05\n",
      "Epoch 147/500\n",
      "24/24 [==============================] - 0s - loss: 1.0872e-05\n",
      "Epoch 148/500\n",
      "24/24 [==============================] - 0s - loss: 1.0732e-05\n",
      "Epoch 149/500\n",
      "24/24 [==============================] - 0s - loss: 1.0595e-05\n",
      "Epoch 150/500\n",
      "24/24 [==============================] - 0s - loss: 1.0460e-05\n",
      "Epoch 151/500\n",
      "24/24 [==============================] - 0s - loss: 1.0328e-05\n",
      "Epoch 152/500\n",
      "24/24 [==============================] - 0s - loss: 1.0198e-05\n",
      "Epoch 153/500\n",
      "24/24 [==============================] - 0s - loss: 1.0071e-05\n",
      "Epoch 154/500\n",
      "24/24 [==============================] - 0s - loss: 9.9453e-06\n",
      "Epoch 155/500\n",
      "24/24 [==============================] - 0s - loss: 9.8222e-06\n",
      "Epoch 156/500\n",
      "24/24 [==============================] - 0s - loss: 9.7014e-06\n",
      "Epoch 157/500\n",
      "24/24 [==============================] - 0s - loss: 9.5827e-06\n",
      "Epoch 158/500\n",
      "24/24 [==============================] - 0s - loss: 9.4661e-06\n",
      "Epoch 159/500\n",
      "24/24 [==============================] - 0s - loss: 9.3515e-06\n",
      "Epoch 160/500\n",
      "24/24 [==============================] - 0s - loss: 9.2389e-06\n",
      "Epoch 161/500\n",
      "24/24 [==============================] - 0s - loss: 9.1283e-06\n",
      "Epoch 162/500\n",
      "24/24 [==============================] - 0s - loss: 9.0195e-06\n",
      "Epoch 163/500\n",
      "24/24 [==============================] - 0s - loss: 8.9126e-06\n",
      "Epoch 164/500\n",
      "24/24 [==============================] - 0s - loss: 8.8075e-06\n",
      "Epoch 165/500\n",
      "24/24 [==============================] - 0s - loss: 8.7042e-06\n",
      "Epoch 166/500\n",
      "24/24 [==============================] - 0s - loss: 8.6026e-06\n",
      "Epoch 167/500\n",
      "24/24 [==============================] - 0s - loss: 8.5029e-06\n",
      "Epoch 168/500\n",
      "24/24 [==============================] - 0s - loss: 8.4051e-06\n",
      "Epoch 169/500\n",
      "24/24 [==============================] - 0s - loss: 8.3097e-06\n",
      "Epoch 170/500\n",
      "24/24 [==============================] - 0s - loss: 8.2182e-06\n",
      "Epoch 171/500\n",
      "24/24 [==============================] - 0s - loss: 8.1358e-06\n",
      "Epoch 172/500\n",
      "24/24 [==============================] - 0s - loss: 8.0790e-06\n",
      "Epoch 173/500\n",
      "24/24 [==============================] - 0s - loss: 8.1025e-06\n",
      "Epoch 174/500\n",
      "24/24 [==============================] - 0s - loss: 8.3895e-06\n",
      "Epoch 175/500\n",
      "24/24 [==============================] - 0s - loss: 9.4917e-06\n",
      "Epoch 176/500\n",
      "24/24 [==============================] - 0s - loss: 1.2755e-05\n",
      "Epoch 177/500\n",
      "24/24 [==============================] - 0s - loss: 1.8317e-05\n",
      "Epoch 178/500\n",
      "24/24 [==============================] - 0s - loss: 1.9542e-05\n",
      "Epoch 179/500\n",
      "24/24 [==============================] - 0s - loss: 9.6545e-06\n",
      "Epoch 180/500\n",
      "24/24 [==============================] - 0s - loss: 9.7739e-06\n",
      "Epoch 181/500\n",
      "24/24 [==============================] - 0s - loss: 1.3001e-05\n",
      "Epoch 182/500\n",
      "24/24 [==============================] - 0s - loss: 7.3604e-06\n",
      "Epoch 183/500\n",
      "24/24 [==============================] - 0s - loss: 1.1275e-05\n",
      "Epoch 184/500\n",
      "24/24 [==============================] - 0s - loss: 7.5295e-06\n",
      "Epoch 185/500\n",
      "24/24 [==============================] - 0s - loss: 9.7158e-06\n",
      "Epoch 186/500\n",
      "24/24 [==============================] - 0s - loss: 7.3535e-06\n",
      "Epoch 187/500\n",
      "24/24 [==============================] - 0s - loss: 8.9440e-06\n",
      "Epoch 188/500\n",
      "24/24 [==============================] - 0s - loss: 7.0241e-06\n",
      "Epoch 189/500\n",
      "24/24 [==============================] - 0s - loss: 8.4337e-06\n",
      "Epoch 190/500\n",
      "24/24 [==============================] - 0s - loss: 6.7578e-06\n",
      "Epoch 191/500\n",
      "24/24 [==============================] - 0s - loss: 7.9044e-06\n",
      "Epoch 192/500\n",
      "24/24 [==============================] - 0s - loss: 6.7559e-06\n",
      "Epoch 193/500\n",
      "24/24 [==============================] - 0s - loss: 7.2308e-06\n",
      "Epoch 194/500\n",
      "24/24 [==============================] - 0s - loss: 6.9153e-06\n",
      "Epoch 195/500\n",
      "24/24 [==============================] - 0s - loss: 6.6266e-06\n",
      "Epoch 196/500\n",
      "24/24 [==============================] - 0s - loss: 6.9284e-06\n",
      "Epoch 197/500\n",
      "24/24 [==============================] - 0s - loss: 6.3364e-06\n",
      "Epoch 198/500\n",
      "24/24 [==============================] - 0s - loss: 6.6579e-06\n",
      "Epoch 199/500\n",
      "24/24 [==============================] - 0s - loss: 6.3209e-06\n",
      "Epoch 200/500\n",
      "24/24 [==============================] - 0s - loss: 6.2741e-06\n",
      "Epoch 201/500\n",
      "24/24 [==============================] - 0s - loss: 6.3136e-06\n",
      "Epoch 202/500\n",
      "24/24 [==============================] - 0s - loss: 6.0342e-06\n",
      "Epoch 203/500\n",
      "24/24 [==============================] - 0s - loss: 6.1400e-06\n",
      "Epoch 204/500\n",
      "24/24 [==============================] - 0s - loss: 5.9670e-06\n",
      "Epoch 205/500\n",
      "24/24 [==============================] - 0s - loss: 5.8946e-06\n",
      "Epoch 206/500\n",
      "24/24 [==============================] - 0s - loss: 5.8996e-06\n",
      "Epoch 207/500\n",
      "24/24 [==============================] - 0s - loss: 5.7388e-06\n",
      "Epoch 208/500\n",
      "24/24 [==============================] - 0s - loss: 5.7400e-06\n",
      "Epoch 209/500\n",
      "24/24 [==============================] - 0s - loss: 5.6662e-06\n",
      "Epoch 210/500\n",
      "24/24 [==============================] - 0s - loss: 5.5646e-06\n",
      "Epoch 211/500\n",
      "24/24 [==============================] - 0s - loss: 5.5703e-06\n",
      "Epoch 212/500\n",
      "24/24 [==============================] - 0s - loss: 5.4569e-06\n",
      "Epoch 213/500\n",
      "24/24 [==============================] - 0s - loss: 5.4211e-06\n",
      "Epoch 214/500\n",
      "24/24 [==============================] - 0s - loss: 5.3862e-06\n",
      "Epoch 215/500\n",
      "24/24 [==============================] - 0s - loss: 5.2824e-06\n",
      "Epoch 216/500\n",
      "24/24 [==============================] - 0s - loss: 5.2878e-06\n",
      "Epoch 217/500\n",
      "24/24 [==============================] - 0s - loss: 5.1922e-06\n",
      "Epoch 218/500\n",
      "24/24 [==============================] - 0s - loss: 5.1588e-06\n",
      "Epoch 219/500\n",
      "24/24 [==============================] - 0s - loss: 5.1203e-06\n",
      "Epoch 220/500\n",
      "24/24 [==============================] - 0s - loss: 5.0422e-06\n",
      "Epoch 221/500\n",
      "24/24 [==============================] - 0s - loss: 5.0289e-06\n",
      "Epoch 222/500\n",
      "24/24 [==============================] - 0s - loss: 4.9560e-06\n",
      "Epoch 223/500\n",
      "24/24 [==============================] - 0s - loss: 4.9211e-06\n",
      "Epoch 224/500\n",
      "24/24 [==============================] - 0s - loss: 4.8803e-06\n",
      "Epoch 225/500\n",
      "24/24 [==============================] - 0s - loss: 4.8221e-06\n",
      "Epoch 226/500\n",
      "24/24 [==============================] - 0s - loss: 4.7945e-06\n",
      "Epoch 227/500\n",
      "24/24 [==============================] - 0s - loss: 4.7402e-06\n",
      "Epoch 228/500\n",
      "24/24 [==============================] - 0s - loss: 4.7022e-06\n",
      "Epoch 229/500\n",
      "24/24 [==============================] - 0s - loss: 4.6632e-06\n",
      "Epoch 230/500\n",
      "24/24 [==============================] - 0s - loss: 4.6169e-06\n",
      "Epoch 231/500\n",
      "24/24 [==============================] - 0s - loss: 4.5817e-06\n",
      "Epoch 232/500\n",
      "24/24 [==============================] - 0s - loss: 4.5401e-06\n",
      "Epoch 233/500\n",
      "24/24 [==============================] - 0s - loss: 4.4997e-06\n",
      "Epoch 234/500\n",
      "24/24 [==============================] - 0s - loss: 4.4648e-06\n",
      "Epoch 235/500\n",
      "24/24 [==============================] - 0s - loss: 4.4232e-06\n",
      "Epoch 236/500\n",
      "24/24 [==============================] - 0s - loss: 4.3882e-06\n",
      "Epoch 237/500\n",
      "24/24 [==============================] - 0s - loss: 4.3515e-06\n",
      "Epoch 238/500\n",
      "24/24 [==============================] - 0s - loss: 4.3128e-06\n",
      "Epoch 239/500\n",
      "24/24 [==============================] - 0s - loss: 4.2812e-06\n",
      "Epoch 240/500\n",
      "24/24 [==============================] - 0s - loss: 4.2413e-06\n",
      "Epoch 241/500\n",
      "24/24 [==============================] - 0s - loss: 4.2103e-06\n",
      "Epoch 242/500\n",
      "24/24 [==============================] - 0s - loss: 4.1740e-06\n",
      "Epoch 243/500\n",
      "24/24 [==============================] - 0s - loss: 4.1400e-06\n",
      "Epoch 244/500\n",
      "24/24 [==============================] - 0s - loss: 4.1084e-06\n",
      "Epoch 245/500\n",
      "24/24 [==============================] - 0s - loss: 4.0728e-06\n",
      "Epoch 246/500\n",
      "24/24 [==============================] - 0s - loss: 4.0429e-06\n",
      "Epoch 247/500\n",
      "24/24 [==============================] - 0s - loss: 4.0088e-06\n",
      "Epoch 248/500\n",
      "24/24 [==============================] - 0s - loss: 3.9781e-06\n",
      "Epoch 249/500\n",
      "24/24 [==============================] - 0s - loss: 3.9468e-06\n",
      "Epoch 250/500\n",
      "24/24 [==============================] - 0s - loss: 3.9150e-06\n",
      "Epoch 251/500\n",
      "24/24 [==============================] - 0s - loss: 3.8858e-06\n",
      "Epoch 252/500\n",
      "24/24 [==============================] - 0s - loss: 3.8544e-06\n",
      "Epoch 253/500\n",
      "24/24 [==============================] - 0s - loss: 3.8255e-06\n",
      "Epoch 254/500\n",
      "24/24 [==============================] - 0s - loss: 3.7957e-06\n",
      "Epoch 255/500\n",
      "24/24 [==============================] - 0s - loss: 3.7665e-06\n",
      "Epoch 256/500\n",
      "24/24 [==============================] - 0s - loss: 3.7384e-06\n",
      "Epoch 257/500\n",
      "24/24 [==============================] - 0s - loss: 3.7094e-06\n",
      "Epoch 258/500\n",
      "24/24 [==============================] - 0s - loss: 3.6820e-06\n",
      "Epoch 259/500\n",
      "24/24 [==============================] - 0s - loss: 3.6539e-06\n",
      "Epoch 260/500\n",
      "24/24 [==============================] - 0s - loss: 3.6268e-06\n",
      "Epoch 261/500\n",
      "24/24 [==============================] - 0s - loss: 3.5999e-06\n",
      "Epoch 262/500\n",
      "24/24 [==============================] - 0s - loss: 3.5729e-06\n",
      "Epoch 263/500\n",
      "24/24 [==============================] - 0s - loss: 3.5470e-06\n",
      "Epoch 264/500\n",
      "24/24 [==============================] - 0s - loss: 3.5205e-06\n",
      "Epoch 265/500\n",
      "24/24 [==============================] - 0s - loss: 3.4952e-06\n",
      "Epoch 266/500\n",
      "24/24 [==============================] - 0s - loss: 3.4695e-06\n",
      "Epoch 267/500\n",
      "24/24 [==============================] - 0s - loss: 3.4445e-06\n",
      "Epoch 268/500\n",
      "24/24 [==============================] - 0s - loss: 3.4197e-06\n",
      "Epoch 269/500\n",
      "24/24 [==============================] - 0s - loss: 3.3950e-06\n",
      "Epoch 270/500\n",
      "24/24 [==============================] - 0s - loss: 3.3709e-06\n",
      "Epoch 271/500\n",
      "24/24 [==============================] - 0s - loss: 3.3467e-06\n",
      "Epoch 272/500\n",
      "24/24 [==============================] - 0s - loss: 3.3233e-06\n",
      "Epoch 273/500\n",
      "24/24 [==============================] - 0s - loss: 3.2996e-06\n",
      "Epoch 274/500\n",
      "24/24 [==============================] - 0s - loss: 3.2766e-06\n",
      "Epoch 275/500\n",
      "24/24 [==============================] - 0s - loss: 3.2536e-06\n",
      "Epoch 276/500\n",
      "24/24 [==============================] - 0s - loss: 3.2310e-06\n",
      "Epoch 277/500\n",
      "24/24 [==============================] - 0s - loss: 3.2086e-06\n",
      "Epoch 278/500\n",
      "24/24 [==============================] - 0s - loss: 3.1864e-06\n",
      "Epoch 279/500\n",
      "24/24 [==============================] - 0s - loss: 3.1646e-06\n",
      "Epoch 280/500\n",
      "24/24 [==============================] - 0s - loss: 3.1429e-06\n",
      "Epoch 281/500\n",
      "24/24 [==============================] - 0s - loss: 3.1215e-06\n",
      "Epoch 282/500\n",
      "24/24 [==============================] - 0s - loss: 3.1003e-06\n",
      "Epoch 283/500\n",
      "24/24 [==============================] - 0s - loss: 3.0794e-06\n",
      "Epoch 284/500\n",
      "24/24 [==============================] - 0s - loss: 3.0587e-06\n",
      "Epoch 285/500\n",
      "24/24 [==============================] - 0s - loss: 3.0382e-06\n",
      "Epoch 286/500\n",
      "24/24 [==============================] - 0s - loss: 3.0179e-06\n",
      "Epoch 287/500\n",
      "24/24 [==============================] - 0s - loss: 2.9979e-06\n",
      "Epoch 288/500\n",
      "24/24 [==============================] - 0s - loss: 2.9781e-06\n",
      "Epoch 289/500\n",
      "24/24 [==============================] - 0s - loss: 2.9584e-06\n",
      "Epoch 290/500\n",
      "24/24 [==============================] - 0s - loss: 2.9391e-06\n",
      "Epoch 291/500\n",
      "24/24 [==============================] - 0s - loss: 2.9198e-06\n",
      "Epoch 292/500\n",
      "24/24 [==============================] - 0s - loss: 2.9009e-06\n",
      "Epoch 293/500\n",
      "24/24 [==============================] - 0s - loss: 2.8821e-06\n",
      "Epoch 294/500\n",
      "24/24 [==============================] - 0s - loss: 2.8635e-06\n",
      "Epoch 295/500\n",
      "24/24 [==============================] - 0s - loss: 2.8451e-06\n",
      "Epoch 296/500\n",
      "24/24 [==============================] - 0s - loss: 2.8269e-06\n",
      "Epoch 297/500\n",
      "24/24 [==============================] - 0s - loss: 2.8089e-06\n",
      "Epoch 298/500\n",
      "24/24 [==============================] - 0s - loss: 2.7911e-06\n",
      "Epoch 299/500\n",
      "24/24 [==============================] - 0s - loss: 2.7735e-06\n",
      "Epoch 300/500\n",
      "24/24 [==============================] - 0s - loss: 2.7560e-06\n",
      "Epoch 301/500\n",
      "24/24 [==============================] - 0s - loss: 2.7388e-06\n",
      "Epoch 302/500\n",
      "24/24 [==============================] - 0s - loss: 2.7217e-06\n",
      "Epoch 303/500\n",
      "24/24 [==============================] - 0s - loss: 2.7048e-06\n",
      "Epoch 304/500\n",
      "24/24 [==============================] - 0s - loss: 2.6880e-06\n",
      "Epoch 305/500\n",
      "24/24 [==============================] - 0s - loss: 2.6715e-06\n",
      "Epoch 306/500\n",
      "24/24 [==============================] - 0s - loss: 2.6551e-06\n",
      "Epoch 307/500\n",
      "24/24 [==============================] - 0s - loss: 2.6388e-06\n",
      "Epoch 308/500\n",
      "24/24 [==============================] - 0s - loss: 2.6228e-06\n",
      "Epoch 309/500\n",
      "24/24 [==============================] - 0s - loss: 2.6069e-06\n",
      "Epoch 310/500\n",
      "24/24 [==============================] - 0s - loss: 2.5911e-06\n",
      "Epoch 311/500\n",
      "24/24 [==============================] - 0s - loss: 2.5755e-06\n",
      "Epoch 312/500\n",
      "24/24 [==============================] - 0s - loss: 2.5601e-06\n",
      "Epoch 313/500\n",
      "24/24 [==============================] - 0s - loss: 2.5448e-06\n",
      "Epoch 314/500\n",
      "24/24 [==============================] - 0s - loss: 2.5297e-06\n",
      "Epoch 315/500\n",
      "24/24 [==============================] - 0s - loss: 2.5147e-06\n",
      "Epoch 316/500\n",
      "24/24 [==============================] - 0s - loss: 2.4999e-06\n",
      "Epoch 317/500\n",
      "24/24 [==============================] - 0s - loss: 2.4852e-06\n",
      "Epoch 318/500\n",
      "24/24 [==============================] - 0s - loss: 2.4706e-06\n",
      "Epoch 319/500\n",
      "24/24 [==============================] - 0s - loss: 2.4562e-06\n",
      "Epoch 320/500\n",
      "24/24 [==============================] - 0s - loss: 2.4420e-06\n",
      "Epoch 321/500\n",
      "24/24 [==============================] - 0s - loss: 2.4279e-06\n",
      "Epoch 322/500\n",
      "24/24 [==============================] - 0s - loss: 2.4139e-06\n",
      "Epoch 323/500\n",
      "24/24 [==============================] - 0s - loss: 2.4000e-06\n",
      "Epoch 324/500\n",
      "24/24 [==============================] - 0s - loss: 2.3863e-06\n",
      "Epoch 325/500\n",
      "24/24 [==============================] - 0s - loss: 2.3727e-06\n",
      "Epoch 326/500\n",
      "24/24 [==============================] - 0s - loss: 2.3592e-06\n",
      "Epoch 327/500\n",
      "24/24 [==============================] - 0s - loss: 2.3459e-06\n",
      "Epoch 328/500\n",
      "24/24 [==============================] - 0s - loss: 2.3327e-06\n",
      "Epoch 329/500\n",
      "24/24 [==============================] - 0s - loss: 2.3196e-06\n",
      "Epoch 330/500\n",
      "24/24 [==============================] - 0s - loss: 2.3066e-06\n",
      "Epoch 331/500\n",
      "24/24 [==============================] - 0s - loss: 2.2938e-06\n",
      "Epoch 332/500\n",
      "24/24 [==============================] - 0s - loss: 2.2810e-06\n",
      "Epoch 333/500\n",
      "24/24 [==============================] - 0s - loss: 2.2684e-06\n",
      "Epoch 334/500\n",
      "24/24 [==============================] - 0s - loss: 2.2559e-06\n",
      "Epoch 335/500\n",
      "24/24 [==============================] - 0s - loss: 2.2436e-06\n",
      "Epoch 336/500\n",
      "24/24 [==============================] - 0s - loss: 2.2313e-06\n",
      "Epoch 337/500\n",
      "24/24 [==============================] - 0s - loss: 2.2192e-06\n",
      "Epoch 338/500\n",
      "24/24 [==============================] - 0s - loss: 2.2071e-06\n",
      "Epoch 339/500\n",
      "24/24 [==============================] - 0s - loss: 2.1952e-06\n",
      "Epoch 340/500\n",
      "24/24 [==============================] - 0s - loss: 2.1833e-06\n",
      "Epoch 341/500\n",
      "24/24 [==============================] - 0s - loss: 2.1716e-06\n",
      "Epoch 342/500\n",
      "24/24 [==============================] - 0s - loss: 2.1600e-06\n",
      "Epoch 343/500\n",
      "24/24 [==============================] - 0s - loss: 2.1485e-06\n",
      "Epoch 344/500\n",
      "24/24 [==============================] - 0s - loss: 2.1371e-06\n",
      "Epoch 345/500\n",
      "24/24 [==============================] - 0s - loss: 2.1258e-06\n",
      "Epoch 346/500\n",
      "24/24 [==============================] - 0s - loss: 2.1146e-06\n",
      "Epoch 347/500\n",
      "24/24 [==============================] - 0s - loss: 2.1035e-06\n",
      "Epoch 348/500\n",
      "24/24 [==============================] - 0s - loss: 2.0925e-06\n",
      "Epoch 349/500\n",
      "24/24 [==============================] - 0s - loss: 2.0816e-06\n",
      "Epoch 350/500\n",
      "24/24 [==============================] - 0s - loss: 2.0709e-06\n",
      "Epoch 351/500\n",
      "24/24 [==============================] - 0s - loss: 2.0604e-06\n",
      "Epoch 352/500\n",
      "24/24 [==============================] - 0s - loss: 2.0503e-06\n",
      "Epoch 353/500\n",
      "24/24 [==============================] - 0s - loss: 2.0409e-06\n",
      "Epoch 354/500\n",
      "24/24 [==============================] - 0s - loss: 2.0332e-06\n",
      "Epoch 355/500\n",
      "24/24 [==============================] - 0s - loss: 2.0294e-06\n",
      "Epoch 356/500\n",
      "24/24 [==============================] - 0s - loss: 2.0351e-06\n",
      "Epoch 357/500\n",
      "24/24 [==============================] - 0s - loss: 2.0644e-06\n",
      "Epoch 358/500\n",
      "24/24 [==============================] - 0s - loss: 2.1535e-06\n",
      "Epoch 359/500\n",
      "24/24 [==============================] - 0s - loss: 2.3903e-06\n",
      "Epoch 360/500\n",
      "24/24 [==============================] - 0s - loss: 2.9886e-06\n",
      "Epoch 361/500\n",
      "24/24 [==============================] - 0s - loss: 4.3210e-06\n",
      "Epoch 362/500\n",
      "24/24 [==============================] - 0s - loss: 6.7512e-06\n",
      "Epoch 363/500\n",
      "24/24 [==============================] - 0s - loss: 8.8087e-06\n",
      "Epoch 364/500\n",
      "24/24 [==============================] - 0s - loss: 7.1818e-06\n",
      "Epoch 365/500\n",
      "24/24 [==============================] - 0s - loss: 2.5787e-06\n",
      "Epoch 366/500\n",
      "24/24 [==============================] - 0s - loss: 3.1217e-06\n",
      "Epoch 367/500\n",
      "24/24 [==============================] - 0s - loss: 4.8527e-06\n",
      "Epoch 368/500\n",
      "24/24 [==============================] - 0s - loss: 2.1875e-06\n",
      "Epoch 369/500\n",
      "24/24 [==============================] - 0s - loss: 3.2430e-06\n",
      "Epoch 370/500\n",
      "24/24 [==============================] - 0s - loss: 3.0657e-06\n",
      "Epoch 371/500\n",
      "24/24 [==============================] - 0s - loss: 2.1363e-06\n",
      "Epoch 372/500\n",
      "24/24 [==============================] - 0s - loss: 3.1596e-06\n",
      "Epoch 373/500\n",
      "24/24 [==============================] - 0s - loss: 1.8904e-06\n",
      "Epoch 374/500\n",
      "24/24 [==============================] - 0s - loss: 2.8506e-06\n",
      "Epoch 375/500\n",
      "24/24 [==============================] - 0s - loss: 1.9093e-06\n",
      "Epoch 376/500\n",
      "24/24 [==============================] - 0s - loss: 2.5723e-06\n",
      "Epoch 377/500\n",
      "24/24 [==============================] - 0s - loss: 1.9031e-06\n",
      "Epoch 378/500\n",
      "24/24 [==============================] - 0s - loss: 2.3790e-06\n",
      "Epoch 379/500\n",
      "24/24 [==============================] - 0s - loss: 1.8847e-06\n",
      "Epoch 380/500\n",
      "24/24 [==============================] - 0s - loss: 2.2367e-06\n",
      "Epoch 381/500\n",
      "24/24 [==============================] - 0s - loss: 1.8569e-06\n",
      "Epoch 382/500\n",
      "24/24 [==============================] - 0s - loss: 2.1371e-06\n",
      "Epoch 383/500\n",
      "24/24 [==============================] - 0s - loss: 1.8203e-06\n",
      "Epoch 384/500\n",
      "24/24 [==============================] - 0s - loss: 2.0577e-06\n",
      "Epoch 385/500\n",
      "24/24 [==============================] - 0s - loss: 1.7974e-06\n",
      "Epoch 386/500\n",
      "24/24 [==============================] - 0s - loss: 1.9794e-06\n",
      "Epoch 387/500\n",
      "24/24 [==============================] - 0s - loss: 1.7867e-06\n",
      "Epoch 388/500\n",
      "24/24 [==============================] - 0s - loss: 1.9067e-06\n",
      "Epoch 389/500\n",
      "24/24 [==============================] - 0s - loss: 1.7797e-06\n",
      "Epoch 390/500\n",
      "24/24 [==============================] - 0s - loss: 1.8419e-06\n",
      "Epoch 391/500\n",
      "24/24 [==============================] - 0s - loss: 1.7744e-06\n",
      "Epoch 392/500\n",
      "24/24 [==============================] - 0s - loss: 1.7842e-06\n",
      "Epoch 393/500\n",
      "24/24 [==============================] - 0s - loss: 1.7682e-06\n",
      "Epoch 394/500\n",
      "24/24 [==============================] - 0s - loss: 1.7370e-06\n",
      "Epoch 395/500\n",
      "24/24 [==============================] - 0s - loss: 1.7550e-06\n",
      "Epoch 396/500\n",
      "24/24 [==============================] - 0s - loss: 1.7035e-06\n",
      "Epoch 397/500\n",
      "24/24 [==============================] - 0s - loss: 1.7353e-06\n",
      "Epoch 398/500\n",
      "24/24 [==============================] - 0s - loss: 1.6782e-06\n",
      "Epoch 399/500\n",
      "24/24 [==============================] - 0s - loss: 1.7128e-06\n",
      "Epoch 400/500\n",
      "24/24 [==============================] - 0s - loss: 1.6594e-06\n",
      "Epoch 401/500\n",
      "24/24 [==============================] - 0s - loss: 1.6870e-06\n",
      "Epoch 402/500\n",
      "24/24 [==============================] - 0s - loss: 1.6463e-06\n",
      "Epoch 403/500\n",
      "24/24 [==============================] - 0s - loss: 1.6605e-06\n",
      "Epoch 404/500\n",
      "24/24 [==============================] - 0s - loss: 1.6337e-06\n",
      "Epoch 405/500\n",
      "24/24 [==============================] - 0s - loss: 1.6371e-06\n",
      "Epoch 406/500\n",
      "24/24 [==============================] - 0s - loss: 1.6207e-06\n",
      "Epoch 407/500\n",
      "24/24 [==============================] - 0s - loss: 1.6153e-06\n",
      "Epoch 408/500\n",
      "24/24 [==============================] - 0s - loss: 1.6077e-06\n",
      "Epoch 409/500\n",
      "24/24 [==============================] - 0s - loss: 1.5961e-06\n",
      "Epoch 410/500\n",
      "24/24 [==============================] - 0s - loss: 1.5930e-06\n",
      "Epoch 411/500\n",
      "24/24 [==============================] - 0s - loss: 1.5795e-06\n",
      "Epoch 412/500\n",
      "24/24 [==============================] - 0s - loss: 1.5779e-06\n",
      "Epoch 413/500\n",
      "24/24 [==============================] - 0s - loss: 1.5642e-06\n",
      "Epoch 414/500\n",
      "24/24 [==============================] - 0s - loss: 1.5626e-06\n",
      "Epoch 415/500\n",
      "24/24 [==============================] - 0s - loss: 1.5502e-06\n",
      "Epoch 416/500\n",
      "24/24 [==============================] - 0s - loss: 1.5472e-06\n",
      "Epoch 417/500\n",
      "24/24 [==============================] - 0s - loss: 1.5369e-06\n",
      "Epoch 418/500\n",
      "24/24 [==============================] - 0s - loss: 1.5323e-06\n",
      "Epoch 419/500\n",
      "24/24 [==============================] - 0s - loss: 1.5237e-06\n",
      "Epoch 420/500\n",
      "24/24 [==============================] - 0s - loss: 1.5179e-06\n",
      "Epoch 421/500\n",
      "24/24 [==============================] - 0s - loss: 1.5107e-06\n",
      "Epoch 422/500\n",
      "24/24 [==============================] - 0s - loss: 1.5040e-06\n",
      "Epoch 423/500\n",
      "24/24 [==============================] - 0s - loss: 1.4979e-06\n",
      "Epoch 424/500\n",
      "24/24 [==============================] - 0s - loss: 1.4907e-06\n",
      "Epoch 425/500\n",
      "24/24 [==============================] - 0s - loss: 1.4851e-06\n",
      "Epoch 426/500\n",
      "24/24 [==============================] - 0s - loss: 1.4779e-06\n",
      "Epoch 427/500\n",
      "24/24 [==============================] - 0s - loss: 1.4724e-06\n",
      "Epoch 428/500\n",
      "24/24 [==============================] - 0s - loss: 1.4653e-06\n",
      "Epoch 429/500\n",
      "24/24 [==============================] - 0s - loss: 1.4599e-06\n",
      "Epoch 430/500\n",
      "24/24 [==============================] - 0s - loss: 1.4532e-06\n",
      "Epoch 431/500\n",
      "24/24 [==============================] - 0s - loss: 1.4476e-06\n",
      "Epoch 432/500\n",
      "24/24 [==============================] - 0s - loss: 1.4411e-06\n",
      "Epoch 433/500\n",
      "24/24 [==============================] - 0s - loss: 1.4356e-06\n",
      "Epoch 434/500\n",
      "24/24 [==============================] - 0s - loss: 1.4293e-06\n",
      "Epoch 435/500\n",
      "24/24 [==============================] - 0s - loss: 1.4237e-06\n",
      "Epoch 436/500\n",
      "24/24 [==============================] - 0s - loss: 1.4177e-06\n",
      "Epoch 437/500\n",
      "24/24 [==============================] - 0s - loss: 1.4121e-06\n",
      "Epoch 438/500\n",
      "24/24 [==============================] - 0s - loss: 1.4062e-06\n",
      "Epoch 439/500\n",
      "24/24 [==============================] - 0s - loss: 1.4006e-06\n",
      "Epoch 440/500\n",
      "24/24 [==============================] - 0s - loss: 1.3949e-06\n",
      "Epoch 441/500\n",
      "24/24 [==============================] - 0s - loss: 1.3893e-06\n",
      "Epoch 442/500\n",
      "24/24 [==============================] - 0s - loss: 1.3837e-06\n",
      "Epoch 443/500\n",
      "24/24 [==============================] - 0s - loss: 1.3782e-06\n",
      "Epoch 444/500\n",
      "24/24 [==============================] - 0s - loss: 1.3727e-06\n",
      "Epoch 445/500\n",
      "24/24 [==============================] - 0s - loss: 1.3672e-06\n",
      "Epoch 446/500\n",
      "24/24 [==============================] - 0s - loss: 1.3619e-06\n",
      "Epoch 447/500\n",
      "24/24 [==============================] - 0s - loss: 1.3565e-06\n",
      "Epoch 448/500\n",
      "24/24 [==============================] - 0s - loss: 1.3512e-06\n",
      "Epoch 449/500\n",
      "24/24 [==============================] - 0s - loss: 1.3458e-06\n",
      "Epoch 450/500\n",
      "24/24 [==============================] - 0s - loss: 1.3406e-06\n",
      "Epoch 451/500\n",
      "24/24 [==============================] - 0s - loss: 1.3353e-06\n",
      "Epoch 452/500\n",
      "24/24 [==============================] - 0s - loss: 1.3302e-06\n",
      "Epoch 453/500\n",
      "24/24 [==============================] - 0s - loss: 1.3250e-06\n",
      "Epoch 454/500\n",
      "24/24 [==============================] - 0s - loss: 1.3199e-06\n",
      "Epoch 455/500\n",
      "24/24 [==============================] - 0s - loss: 1.3148e-06\n",
      "Epoch 456/500\n",
      "24/24 [==============================] - 0s - loss: 1.3097e-06\n",
      "Epoch 457/500\n",
      "24/24 [==============================] - 0s - loss: 1.3047e-06\n",
      "Epoch 458/500\n",
      "24/24 [==============================] - 0s - loss: 1.2997e-06\n",
      "Epoch 459/500\n",
      "24/24 [==============================] - 0s - loss: 1.2947e-06\n",
      "Epoch 460/500\n",
      "24/24 [==============================] - 0s - loss: 1.2898e-06\n",
      "Epoch 461/500\n",
      "24/24 [==============================] - 0s - loss: 1.2849e-06\n",
      "Epoch 462/500\n",
      "24/24 [==============================] - 0s - loss: 1.2801e-06\n",
      "Epoch 463/500\n",
      "24/24 [==============================] - 0s - loss: 1.2752e-06\n",
      "Epoch 464/500\n",
      "24/24 [==============================] - 0s - loss: 1.2704e-06\n",
      "Epoch 465/500\n",
      "24/24 [==============================] - 0s - loss: 1.2656e-06\n",
      "Epoch 466/500\n",
      "24/24 [==============================] - 0s - loss: 1.2609e-06\n",
      "Epoch 467/500\n",
      "24/24 [==============================] - 0s - loss: 1.2561e-06\n",
      "Epoch 468/500\n",
      "24/24 [==============================] - 0s - loss: 1.2515e-06\n",
      "Epoch 469/500\n",
      "24/24 [==============================] - 0s - loss: 1.2468e-06\n",
      "Epoch 470/500\n",
      "24/24 [==============================] - 0s - loss: 1.2422e-06\n",
      "Epoch 471/500\n",
      "24/24 [==============================] - 0s - loss: 1.2375e-06\n",
      "Epoch 472/500\n",
      "24/24 [==============================] - 0s - loss: 1.2330e-06\n",
      "Epoch 473/500\n",
      "24/24 [==============================] - 0s - loss: 1.2284e-06\n",
      "Epoch 474/500\n",
      "24/24 [==============================] - 0s - loss: 1.2239e-06\n",
      "Epoch 475/500\n",
      "24/24 [==============================] - 0s - loss: 1.2194e-06\n",
      "Epoch 476/500\n",
      "24/24 [==============================] - 0s - loss: 1.2149e-06\n",
      "Epoch 477/500\n",
      "24/24 [==============================] - 0s - loss: 1.2105e-06\n",
      "Epoch 478/500\n",
      "24/24 [==============================] - 0s - loss: 1.2061e-06\n",
      "Epoch 479/500\n",
      "24/24 [==============================] - 0s - loss: 1.2017e-06\n",
      "Epoch 480/500\n",
      "24/24 [==============================] - 0s - loss: 1.1973e-06\n",
      "Epoch 481/500\n",
      "24/24 [==============================] - 0s - loss: 1.1930e-06\n",
      "Epoch 482/500\n",
      "24/24 [==============================] - 0s - loss: 1.1886e-06\n",
      "Epoch 483/500\n",
      "24/24 [==============================] - 0s - loss: 1.1843e-06\n",
      "Epoch 484/500\n",
      "24/24 [==============================] - 0s - loss: 1.1801e-06\n",
      "Epoch 485/500\n",
      "24/24 [==============================] - 0s - loss: 1.1758e-06\n",
      "Epoch 486/500\n",
      "24/24 [==============================] - 0s - loss: 1.1716e-06\n",
      "Epoch 487/500\n",
      "24/24 [==============================] - 0s - loss: 1.1674e-06\n",
      "Epoch 488/500\n",
      "24/24 [==============================] - 0s - loss: 1.1633e-06\n",
      "Epoch 489/500\n",
      "24/24 [==============================] - 0s - loss: 1.1591e-06\n",
      "Epoch 490/500\n",
      "24/24 [==============================] - 0s - loss: 1.1550e-06\n",
      "Epoch 491/500\n",
      "24/24 [==============================] - 0s - loss: 1.1509e-06\n",
      "Epoch 492/500\n",
      "24/24 [==============================] - 0s - loss: 1.1468e-06\n",
      "Epoch 493/500\n",
      "24/24 [==============================] - 0s - loss: 1.1428e-06\n",
      "Epoch 494/500\n",
      "24/24 [==============================] - 0s - loss: 1.1387e-06\n",
      "Epoch 495/500\n",
      "24/24 [==============================] - 0s - loss: 1.1347e-06\n",
      "Epoch 496/500\n",
      "24/24 [==============================] - 0s - loss: 1.1307e-06\n",
      "Epoch 497/500\n",
      "24/24 [==============================] - 0s - loss: 1.1268e-06\n",
      "Epoch 498/500\n",
      "24/24 [==============================] - 0s - loss: 1.1228e-06\n",
      "Epoch 499/500\n",
      "24/24 [==============================] - 0s - loss: 1.1189e-06\n",
      "Epoch 500/500\n",
      "24/24 [==============================] - 0s - loss: 1.1150e-06\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x7fc53eed9358>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# training\n",
    "# simple function\n",
    "#f =  lambda x: numpy.sin(x)\n",
    "f = lambda x: numpy.sin(x) *  x ** 0.1\n",
    "data_range = (0, 200, inteval)\n",
    "X_train, Y_train = gen_train_data(f, data_range, feature_length, seq_length)\n",
    "\n",
    "# train model\n",
    "model.fit(X_train, Y_train, nb_epoch=500, batch_size=32)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "window.mpl = {};\n",
       "\n",
       "mpl.get_websocket_type = function() {\n",
       "    if (typeof(WebSocket) !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof(MozWebSocket) !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert('Your browser does not have WebSocket support.' +\n",
       "              'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "              'Firefox 4 and 5 are also supported but you ' +\n",
       "              'have to enable WebSockets in about:config.');\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = (this.ws.binaryType != undefined);\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById(\"mpl-warnings\");\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent = (\n",
       "                \"This browser does not support binary websocket messages. \" +\n",
       "                    \"Performance may be slow.\");\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = $('<div/>');\n",
       "    this._root_extra_style(this.root)\n",
       "    this.root.attr('style', 'display: inline-block');\n",
       "\n",
       "    $(parent_element).append(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen =  function () {\n",
       "            fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
       "            fig.send_message(\"send_image_mode\", {});\n",
       "            fig.send_message(\"refresh\", {});\n",
       "        }\n",
       "\n",
       "    this.imageObj.onload = function() {\n",
       "            if (fig.image_mode == 'full') {\n",
       "                // Full images could contain transparency (where diff images\n",
       "                // almost always do), so we need to clear the canvas so that\n",
       "                // there is no ghosting.\n",
       "                fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "            }\n",
       "            fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "        };\n",
       "\n",
       "    this.imageObj.onunload = function() {\n",
       "        this.ws.close();\n",
       "    }\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_header = function() {\n",
       "    var titlebar = $(\n",
       "        '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
       "        'ui-helper-clearfix\"/>');\n",
       "    var titletext = $(\n",
       "        '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
       "        'text-align: center; padding: 3px;\"/>');\n",
       "    titlebar.append(titletext)\n",
       "    this.root.append(titlebar);\n",
       "    this.header = titletext[0];\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = $('<div/>');\n",
       "\n",
       "    canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
       "\n",
       "    function canvas_keyboard_event(event) {\n",
       "        return fig.key_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    canvas_div.keydown('key_press', canvas_keyboard_event);\n",
       "    canvas_div.keyup('key_release', canvas_keyboard_event);\n",
       "    this.canvas_div = canvas_div\n",
       "    this._canvas_extra_style(canvas_div)\n",
       "    this.root.append(canvas_div);\n",
       "\n",
       "    var canvas = $('<canvas/>');\n",
       "    canvas.addClass('mpl-canvas');\n",
       "    canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
       "\n",
       "    this.canvas = canvas[0];\n",
       "    this.context = canvas[0].getContext(\"2d\");\n",
       "\n",
       "    var rubberband = $('<canvas/>');\n",
       "    rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
       "\n",
       "    var pass_mouse_events = true;\n",
       "\n",
       "    canvas_div.resizable({\n",
       "        start: function(event, ui) {\n",
       "            pass_mouse_events = false;\n",
       "        },\n",
       "        resize: function(event, ui) {\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "        stop: function(event, ui) {\n",
       "            pass_mouse_events = true;\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "    });\n",
       "\n",
       "    function mouse_event_fn(event) {\n",
       "        if (pass_mouse_events)\n",
       "            return fig.mouse_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    rubberband.mousedown('button_press', mouse_event_fn);\n",
       "    rubberband.mouseup('button_release', mouse_event_fn);\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband.mousemove('motion_notify', mouse_event_fn);\n",
       "\n",
       "    rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
       "    rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
       "\n",
       "    canvas_div.on(\"wheel\", function (event) {\n",
       "        event = event.originalEvent;\n",
       "        event['data'] = 'scroll'\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        mouse_event_fn(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.append(canvas);\n",
       "    canvas_div.append(rubberband);\n",
       "\n",
       "    this.rubberband = rubberband;\n",
       "    this.rubberband_canvas = rubberband[0];\n",
       "    this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
       "    this.rubberband_context.strokeStyle = \"#000000\";\n",
       "\n",
       "    this._resize_canvas = function(width, height) {\n",
       "        // Keep the size of the canvas, canvas container, and rubber band\n",
       "        // canvas in synch.\n",
       "        canvas_div.css('width', width)\n",
       "        canvas_div.css('height', height)\n",
       "\n",
       "        canvas.attr('width', width);\n",
       "        canvas.attr('height', height);\n",
       "\n",
       "        rubberband.attr('width', width);\n",
       "        rubberband.attr('height', height);\n",
       "    }\n",
       "\n",
       "    // Set the figure to an initial 600x600px, this will subsequently be updated\n",
       "    // upon first draw.\n",
       "    this._resize_canvas(600, 600);\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus () {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            // put a spacer in here.\n",
       "            continue;\n",
       "        }\n",
       "        var button = $('<button/>');\n",
       "        button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
       "                        'ui-button-icon-only');\n",
       "        button.attr('role', 'button');\n",
       "        button.attr('aria-disabled', 'false');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "\n",
       "        var icon_img = $('<span/>');\n",
       "        icon_img.addClass('ui-button-icon-primary ui-icon');\n",
       "        icon_img.addClass(image);\n",
       "        icon_img.addClass('ui-corner-all');\n",
       "\n",
       "        var tooltip_span = $('<span/>');\n",
       "        tooltip_span.addClass('ui-button-text');\n",
       "        tooltip_span.html(tooltip);\n",
       "\n",
       "        button.append(icon_img);\n",
       "        button.append(tooltip_span);\n",
       "\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    var fmt_picker_span = $('<span/>');\n",
       "\n",
       "    var fmt_picker = $('<select/>');\n",
       "    fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
       "    fmt_picker_span.append(fmt_picker);\n",
       "    nav_element.append(fmt_picker_span);\n",
       "    this.format_dropdown = fmt_picker[0];\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = $(\n",
       "            '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
       "        fmt_picker.append(option)\n",
       "    }\n",
       "\n",
       "    // Add hover states to the ui-buttons\n",
       "    $( \".ui-button\" ).hover(\n",
       "        function() { $(this).addClass(\"ui-state-hover\");},\n",
       "        function() { $(this).removeClass(\"ui-state-hover\");}\n",
       "    );\n",
       "\n",
       "    var status_bar = $('<span class=\"mpl-message\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_message = function(type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function() {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
       "    }\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1]);\n",
       "        fig.send_message(\"refresh\", {});\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
       "    var x0 = msg['x0'];\n",
       "    var y0 = fig.canvas.height - msg['y0'];\n",
       "    var x1 = msg['x1'];\n",
       "    var y1 = fig.canvas.height - msg['y1'];\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0, 0, fig.canvas.width, fig.canvas.height);\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch(cursor)\n",
       "    {\n",
       "    case 0:\n",
       "        cursor = 'pointer';\n",
       "        break;\n",
       "    case 1:\n",
       "        cursor = 'default';\n",
       "        break;\n",
       "    case 2:\n",
       "        cursor = 'crosshair';\n",
       "        break;\n",
       "    case 3:\n",
       "        cursor = 'move';\n",
       "        break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message(\"ack\", {});\n",
       "}\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = \"image/png\";\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src);\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data);\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "        else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig[\"handle_\" + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "}\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function(e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e)\n",
       "        e = window.event;\n",
       "    if (e.target)\n",
       "        targ = e.target;\n",
       "    else if (e.srcElement)\n",
       "        targ = e.srcElement;\n",
       "    if (targ.nodeType == 3) // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "\n",
       "    // jQuery normalizes the pageX and pageY\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    // offset() returns the position of the element relative to the document\n",
       "    var x = e.pageX - $(targ).offset().left;\n",
       "    var y = e.pageY - $(targ).offset().top;\n",
       "\n",
       "    return {\"x\": x, \"y\": y};\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys (original) {\n",
       "  return Object.keys(original).reduce(function (obj, key) {\n",
       "    if (typeof original[key] !== 'object')\n",
       "        obj[key] = original[key]\n",
       "    return obj;\n",
       "  }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function(event, name) {\n",
       "    var canvas_pos = mpl.findpos(event)\n",
       "\n",
       "    if (name === 'button_press')\n",
       "    {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x;\n",
       "    var y = canvas_pos.y;\n",
       "\n",
       "    this.send_message(name, {x: x, y: y, button: event.button,\n",
       "                             step: event.step,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.key_event = function(event, name) {\n",
       "\n",
       "    // Prevent repeat events\n",
       "    if (name == 'key_press')\n",
       "    {\n",
       "        if (event.which === this._key)\n",
       "            return;\n",
       "        else\n",
       "            this._key = event.which;\n",
       "    }\n",
       "    if (name == 'key_release')\n",
       "        this._key = null;\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which != 17)\n",
       "        value += \"ctrl+\";\n",
       "    if (event.altKey && event.which != 18)\n",
       "        value += \"alt+\";\n",
       "    if (event.shiftKey && event.which != 16)\n",
       "        value += \"shift+\";\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, {key: value,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
       "    if (name == 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message(\"toolbar_button\", {name: name});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to  previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
       "\n",
       "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function() {\n",
       "        comm.close()\n",
       "    };\n",
       "    ws.send = function(m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function(msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overriden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data'])\n",
       "    });\n",
       "    return ws;\n",
       "}\n",
       "\n",
       "mpl.mpl_figure_comm = function(comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = $(\"#\" + id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm)\n",
       "\n",
       "    function ondownload(figure, format) {\n",
       "        window.open(figure.imageObj.src);\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy,\n",
       "                           ondownload,\n",
       "                           element.get(0));\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element.get(0);\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error(\"Failed to find cell for figure\", id, fig);\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    var output_index = fig.cell_info[2]\n",
       "    var cell = fig.cell_info[0];\n",
       "\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
       "    fig.root.unbind('remove')\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable()\n",
       "    $(fig.parent_element).html('<img src=\"' + dataURL + '\">');\n",
       "    fig.close_ws(fig, msg);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.close_ws = function(fig, msg){\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\">';\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message(\"ack\", {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () { fig.push_to_output() }, 1000);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items){\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) { continue; };\n",
       "\n",
       "        var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
       "    var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
       "    button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
       "    button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
       "    buttongrp.append(button);\n",
       "    var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
       "    titlebar.prepend(buttongrp);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(el){\n",
       "    var fig = this\n",
       "    el.on(\"remove\", function(){\n",
       "\tfig.close_ws(fig, {});\n",
       "    });\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(el){\n",
       "    // this is important to make the div 'focusable\n",
       "    el.attr('tabindex', 0)\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    }\n",
       "    else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager)\n",
       "        manager = IPython.keyboard_manager;\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which == 13) {\n",
       "        this.canvas_div.blur();\n",
       "        event.shiftKey = false;\n",
       "        // Send a \"J\" for go to next cell\n",
       "        event.which = 74;\n",
       "        event.keyCode = 74;\n",
       "        manager.command_mode();\n",
       "        manager.handle_keydown(event);\n",
       "    }\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.find_output_cell = function(html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i=0; i<ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code'){\n",
       "            for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] == html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel != null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7fc529bf5eb8>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Z = model.predict(numpy.asarray(X_train[0])[None,:])\n",
    "#print(numpy.sqrt(numpy.mean((Z.flatten() - Y_train[0].flatten())**2)))\n",
    "\n",
    "s = feature_length // 2\n",
    "test_num = 30\n",
    "\n",
    "# test\n",
    "start_pos = 200\n",
    "test_range = numpy.linspace(start_pos, start_pos + inteval * feature_length, feature_length)\n",
    "X_test = numpy.asarray(f(test_range)).T[None, None, :]\n",
    "predict_range = numpy.linspace(start_pos + inteval * feature_length, \n",
    "                               start_pos + inteval * feature_length + inteval * s * test_num, s * test_num)\n",
    "Y_test = f(predict_range)\n",
    "\n",
    "pre_x = X_test\n",
    "X_predict = []\n",
    "X_true = []\n",
    "for i in range(test_num):\n",
    "    Z = model.predict(X_test)\n",
    "    pre_x = numpy.hstack((pre_x[0,0,s:], Z[0,-1,s:]))[None, None, :]\n",
    "    X_test = numpy.hstack((X_test, pre_x))\n",
    "    Z = Z.flatten()\n",
    "    X_predict = numpy.hstack((X_predict, Z[-s:]))\n",
    "\n",
    "plt.plot(predict_range, X_predict, label='predict')\n",
    "plt.plot(predict_range, Y_test, label='true')\n",
    "#plt.ylim([-1, 1])\n",
    "plt.legend()\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
